<?php
require_once './device/mysql.php';
require_once './device/check.php';  //导入key检测函数
class check extends Check_key
{
  public function check_key()
  {
    return parent::check_key();
  }
}
class UserInfo extends MySQL
{
  public function get_username($key)
  {
    return parent::get_username($key);
  }
}
$check = new check();
$ID = $check->check_key(); //如果key存在且正确，返回用户ID，否则会返回false
if ($ID != false) {
  $key = $_GET['key'];
  $mysql = new UserInfo();
  $name=$mysql->get_username($key);
  echo <<<EOF
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title>用户管理</title>
  <meta name="renderer" content="webkit" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <link href="https://cdn.staticfile.org/layui/2.8.18/css/layui.css" rel="stylesheet" />
  <link rel="stylesheet" href="https://at.alicdn.com/t/c/font_4315803_juca0b2h9f.css">
  <link rel="stylesheet" href="./css/login.css">
</head>

<body>
  <div class="layui-layout layui-layout-admin">
    <div class="layui-header">
    <a href="http://bluespace.nrhs.link/">
      <div class="layui-logo layui-hide-xs layui-bg-black">BlueSpace <span class="layui-badge">户外监护</span></div>
      </a>
      <!-- 头部区域（可配合layui 已有的水平导航） -->
      <ul class="layui-nav layui-layout-left">
        <!-- 移动端显示 -->
        <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
          <i class="layui-icon layui-icon-spread-left"></i>
        </li>
        <li class="layui-nav-item layui-hide-xs">
          <a href="javascript:;">设备1</a>
        </li>
        <li class="layui-nav-item layui-hide-xs">
          <a href="javascript:;">设备2</a>
        </li>
        <li class="layui-nav-item layui-hide-xs">
          <a href="javascript:;">设备3</a>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">管理设备</a>
          <dl class="layui-nav-child">
            <dd><a href="javascript:;">设备1</a></dd>
            <dd><a href="javascript:;">设备2</a></dd>
            <dd><a href="javascript:;">设备3</a></dd>
          </dl>
        </li>
      </ul>
      <ul class="layui-nav layui-layout-right">
        <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
          <a href="javascript:;">
            <img src="./images/users.jpg" class="layui-nav-img" />
            $name
          </a>
          <dl class="layui-nav-child">
            <dd><a href="javascript:;">个人信息</a></dd>
            <dd><a href="javascript:;">设置</a></dd>
            <dd><a href="javascript:;">注销</a></dd>
          </dl>
        </li>
        <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
          <a href="javascript:;">
            <i class="layui-icon layui-icon-more-vertical"></i>
          </a>
        </li>
      </ul>
    </div>
    <div class="layui-side layui-bg-black">
      <div class="layui-side-scroll">
        <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
        <ul class="layui-nav layui-nav-tree layui-nav-itemed" lay-filter="test">
          <li class="layui-nav-item">
            <a href="./device/view.php?key=$key" target="bowser_iframe">
            <i class="iconfont icon-shuju"></i>
            数据预览
            </a>
          </li>
          <li class="layui-nav-item">
            <a href="javascript:;"><i class="iconfont icon-ditu"></i>地图数据</a>
            <dl class="layui-nav-child">
              <dd><a href="./location.php?key=$key" target="bowser_iframe">实时地图</a></dd>
              <dd><a href="./device/path.php?key=$key" target="bowser_iframe">历史轨迹</a></dd>
            </dl>
          </li>
          <li class="layui-nav-item">
            <a href="javascript:;"><i class="iconfont icon-yujing"></i>预警区域</a>
            <dl class="layui-nav-child">
              <dd><a href="./manage.php?key=$key" target="bowser_iframe">管理区域</a></dd>
              <dd><a href="./device/AddRD.php?key=$key" target="bowser_iframe">修改与添加</a></dd>
            </dl>
          </li>
          <li class="layui-nav-item ">
            <a class="" href="javascript:;"><i class="iconfont icon-bangzhu"></i>使用帮助</a>
            <dl class="layui-nav-child">
              <dd><a href="javascript:;">快速开始</a></dd>
              <dd><a href="javascript:;">常见问题</a></dd>
            </dl>
          </li>
          <li class="layui-nav-item">
            <a href="javascript:;"><i class="iconfont icon-shujuku"></i>数据库管理</a>
          </li>
          <li class="layui-nav-item">
            <a href="https://blog.nrhs.eu.org/2022/12/16/local_analyse/" target="bowser_iframe"><i class="iconfont icon-kaiyuan"></i>开源与反馈</a>
          </li>
        </ul>
      </div>
    </div>
    <div class="layui-body">
      <!-- 内容主体区域 -->
      <div style="padding: 15px">
        <!--<blockquote class="layui-elem-quote layui-text">
          建议使用桌面浏览器访问修改区域
        </blockquote>-->
        <div class="iframe_div">
          <iframe name="bowser_iframe"
            src="./device/view.php?key=$key"
            width="100%" height="100%" scrolling="auto">
          </iframe>
        </div>
        <!--底部-->
      </div>
    </div>
  </div>

  <script src="https://cdn.staticfile.org/layui/2.8.18/layui.js"></script>
  <script>
    //JS
    layui.use(['element', 'layer', 'util'], function () {
      var element = layui.element;
      var layer = layui.layer;
      var util = layui.util;
      var $ = layui.$;

      //头部事件
      util.event('lay-header-event', {
        menuLeft: function (othis) {
          // 左侧菜单事件
          layer.msg('展开左侧菜单的操作', { icon: 0 });
        },
        menuRight: function () {
          // 右侧菜单事件
          layer.open({
            type: 1,
            title: '更多',
            content: '<div style="padding: 15px;">通知测试:V1.3.22</div>',
            area: ['260px', '100%'],
            offset: 'rt', // 右上角
            anim: 'slideLeft', // 从右侧抽屉滑出
            shadeClose: true,
            scrollbar: false,
          });
        },
      });
    });
  </script>
</body>

</html>
EOF;
} else {
  $url = "register.php";
  echo "<script type='text/javascript'>";
  echo "window.location.href='$url'";
  echo "</script>";
  exit;
}
